from django.db import models


# Create your models here.
class BaseModel(models.Model):
    created_time = models.DateTimeField("创建时间", auto_now_add=True)
    updated_time = models.DateTimeField("更新时间", auto_now=True)


# 部门
class Department(BaseModel):
    """
    部门
    """
    name = models.CharField("部门名称", max_length=30)

    class Meta:
        db_table = 'department'

    def __str__(self):
        return self.name


# 职责
class Duty(BaseModel):
    """
    职务
    """
    name = models.CharField(max_length=30, verbose_name='职务名称')

    def __str__(self):
        return self.name

    class Meta:
        db_table = 'duty'


# 员工模型类
class Staff(models.Model):  # 不能也继承BaseModel，会冲突
    """
    员工
    """
    SEX_CHOICE = (
        (1, '男'),
        (2, '女')
    )

    name = models.CharField(max_length=30, verbose_name='姓名')
    sex = models.SmallIntegerField(choices=SEX_CHOICE, default=1, verbose_name='性别')
    phone = models.CharField(max_length=11, verbose_name='手机号')
    email = models.CharField(max_length=60, verbose_name='邮箱')

    # 外键
    department = models.ForeignKey(Department, on_delete=models.CASCADE)
    duty = models.ForeignKey(Duty, on_delete=models.CASCADE)

    def __str__(self):
        return self.name

    class Meta:
        db_table = 'staff'